#include <graphics/Sprite.h>

namespace ne
{
    Sprite::Sprite(const std::string &name)
        : Object(name),
          mSpriteType(SPT_COMMON)
    {
    }

    void Sprite::setSpriteType(const SpriteType spt)
    {
        mSpriteType = spt;
    }

    SpriteType Sprite::getSpriteType() const
    {
        return mSpriteType;
    }

    Vector4 Sprite::getTexCoord() const
    {
        return Vector4(texCoords[0].x, texCoords[0].y,
                       texCoords[1].x, texCoords[1].y);
    }

    void Sprite::setTexCoord(const Vector4 &t01)
    {
        texCoords[0].x = t01.x;
        texCoords[0].y = t01.y;
        texCoords[1].x = t01.z;
        texCoords[1].y = t01.w;
    }

    void Sprite::setTexCoord(const Vector2 &t0, const Vector2 &t1)
    {
        texCoords[0] = t0;
        texCoords[1] = t1;
    }

    void Sprite::setTexCoord(const real u0, const real v0,
                             const real u1, const real v1)
    {
        texCoords[0].x = u0;
        texCoords[0].y = v0;
        texCoords[1].x = u1;
        texCoords[1].y = v1;
    }

    void Sprite::resetTexCoord()
    {
        texCoords[0] = Vector2::ZERO;
        texCoords[1] = Vector2::ONE;
    }

    Vector4 Sprite::getSlicedTexCoord() const
    {
        return Vector4(slicedTexCoords[0].x, slicedTexCoords[0].y,
                       slicedTexCoords[1].x, slicedTexCoords[1].y);
    }

    void Sprite::setSlicedTexCoord(const Vector4 &t01)
    {
        slicedTexCoords[0].x = t01.x;
        slicedTexCoords[0].y = t01.y;
        slicedTexCoords[1].x = t01.z;
        slicedTexCoords[1].y = t01.w;
    }

    void Sprite::setSlicedTexCoord(const Vector2 &t0, const Vector2 &t1)
    {
        slicedTexCoords[0] = t0;
        slicedTexCoords[1] = t1;
    }

    void Sprite::setSlicedTexCoord(const real u0, const real v0,
                                   const real u1, const real v1)
    {
        slicedTexCoords[0].x = u0;
        slicedTexCoords[0].y = v0;
        slicedTexCoords[1].x = u1;
        slicedTexCoords[1].y = v1;
    }

    void Sprite::resetSlicedTexCoord()
    {
        slicedTexCoords[0] = Vector2::ZERO;
        slicedTexCoords[1] = Vector2::ONE;
    }

    Sprite::~Sprite()
    {
    }

    SpriteType Sprite::GetSpriteType(const std::string &str)
    {
        if (str == "COMMON") return SPT_COMMON;
        else if (str == "SLICED") return SPT_SLICED;
        return SPT_COMMON;
    }
}
